#include"comm.h"

int main()
{
  key_t k = ftok(PATHNAME, PROJ_ID);
  if(k < 0)
  {
    printf("ftok error\n");
    return 1;
  }
  printf("key :%d\n",k);

  int shmid = shmget(k, SIZE, IPC_CREAT | IPC_EXCL | 0644);
  if(shmid < 0){
    perror("shmget");
    return 2;
  }
  printf("shmid: %d\n", shmid);

  // rm shmid  
  //sleep(5);
  //void *shmat(int shmid, const void *shmaddr, int shmflg);
  char *str = (char*)shmat(shmid, NULL, 0);
  //sleep(5);
  while(1){
    printf("client send messge:%s\n", str);
    sleep(1);
  }
  shmdt(str);
  //sleep(5);
  
  shmctl(shmid, IPC_RMID, NULL); //shmget的返回值
  //sleep(5);

  return 0;
}
